package com.example.controller;
import com.example.common.Result;
import com.example.common.ResultUtils;
import com.example.dto.UserRegisterRequest;
import com.example.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/user")
public class UserController
{

    @Resource
    private UserService userService;

    /**
     * 演示：用户注册成功，并发送注册消息
     * @param req
     * @return
     */
    @PostMapping("/register")
    public Result<String> register(@Validated @RequestBody UserRegisterRequest req)
    {
        return ResultUtils.success(this.userService.register(req));
    }


    /**
     * 演示：用户注册的事务中有异常，消息投递会被自动取消
     * @param req
     * @return
     */
    @PostMapping("/registerError")
    public Result<String> registerError(@Validated @RequestBody UserRegisterRequest req)
    {
        return ResultUtils.success(this.userService.registerError(req));
    }

}
